package me.dwliu.lab.demo.webflux.controller;

import me.dwliu.lab.demo.webflux.model.Employee;
import me.dwliu.lab.demo.webflux.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@RestController
@RequestMapping("employees")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;

    @PostMapping
    public Mono<Employee> save(@RequestBody Employee entity) {
        return employeeService.create(entity);
    }

    @PutMapping
    public Mono<Employee> update(@RequestBody Employee entity) {
        return employeeService.update(entity);
    }

    @DeleteMapping("/{id}")
    public Mono<Void> delete(@PathVariable("id") Long id) {
        return employeeService.delete(id);
    }

    @GetMapping("/{id}")
    public Mono<Employee> findById(@PathVariable("id") Long id) {
        return employeeService.findById(id);
    }

    @GetMapping
    public Flux<Employee> findAll() {
        return employeeService.findAll();
    }


}
